package com.google.code.msgbooster.servlet.extension;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import com.google.appengine.api.datastore.Link;
import com.google.code.msgbooster.core.DB;
import com.google.code.msgbooster.model.extension.Collector;
import com.google.code.msgbooster.model.extension.Consumer;
import com.google.code.msgbooster.model.extension.Guide;
import com.google.code.msgbooster.model.extension.Relationship;
import com.google.code.msgbooster.model.extension.Transponder;
import com.google.code.msgbooster.servlet.Meta;

public final class Test extends Meta {

	@Override
	protected void execute(ServletConfig servletConfig) throws ServletException {
		Guide g = new Guide();

		g.setResource(new Link("http://t.dianping.com/rss/guangzhou"));

		g.setDetector("DETECTOR_XML");
		g.setClue("/rss/channel/item");
		g.setContentElement("title");
		g.setLinkElement("link");		

		DB.make(getPersistenceManager(), g);
		
		Collector c = new Collector();
		c.setTitle("Tuangou");
		c.addKey(c.getGuide(), g.getKey());
		
		DB.make(getPersistenceManager(), c);
		
		Consumer consumer = new Consumer();
		consumer.setConsumerKey("123");
		consumer.setConsumerSecret("456");
		consumer.setDispatcher("class");
		
		DB.make(getPersistenceManager(), consumer);
		
		Transponder t = new Transponder();
		
		t.setConsumer(t.addKey(t.getConsumer(), consumer.getKey()));
		DB.make(getPersistenceManager(), t);
		
		Relationship r = new Relationship();
		r.setTransponder(t.getKey());
		r.setCollector(c.getKey());
		
		DB.make(getPersistenceManager(), r);

		
		
//		PersistenceManager pm = getPersistenceManager();
//		DB.truncate(pm, Collector.class);
//		DB.truncate(pm, Guide.class);
//		
//		Guide g = new Guide();
//		g.setDetector("123");
//		List<String> tag = new ArrayList<String>();
//		tag.add("a");
//		tag.add("b");
//		g.setTag(tag);
//		DB.make(pm, g);
//		g = new Guide();
//		g.setDetector("123");
//		tag = new ArrayList<String>();
//		tag.add("a");
//		tag.add("b");
//		tag.add("c");
//		g.setTag(tag);
//		DB.make(pm, g);
//		
//		Query query = pm.newQuery(Guide.class);
//		query.setFilter("tag == 'a' && tag=='b' && tag=='c'");
//		List<Guide> results = (List<Guide>) query.execute();
//		System.out.println(results.size());


	}

}
